package com.zzq.demo.retry;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.Random;
import java.util.concurrent.Callable;

/**
 * @author: zhaoziqian
 * @description: TODO
 * @date: 2019/10/21 9:56 下午
 **/
@Component
@Slf4j
public class JobHander implements Callable<Model> {

    @Override
    public Model call() throws Exception {

        int result = (int) (new Random().nextDouble() * 10);
        log.info("开始工作---------》 result:" + result);

        if (result % 3 == 0) {
            throw new Exception("result % 3 == 0");
        }

        if (result == 7) {
            Test.model.setCount(Test.model.getCount() + 1);
            return Test.model;
        }

        if (result % 2 == 0) {
            throw new Exception("result % 2 == 0");
        }
        if (result == 1 || result == 5) {
            Test.model.setCount(Test.model.getCount() + 1);
            return Test.model;
        }
        Test.model.setCount(Test.model.getCount() + 1);
        return Test.model;
    }
}
